<template>
    <div class="acceptance-registration-increase">
        <!-- 药品流通任务受理 -->
            <!-- 新增弹窗 -->
        <a-modal
        class="acceptance-modal flow-path-model-box"
        :visible="visibleShow" 
        :title="parameterData.sqsxid?'办理':'新增'"
        :maskClosable="false"
        :closable="false"
        :destroyOnClose="true"
        :forceRender="true"
        width="100%"
        wrapClassName="full-modal"
        >
            <a-spin size="large" :spinning="modalSpinningPrice" :key="spinningKey">
                <div style="width: 100%; background-color: #fff;position: fixed; top: 0;z-index: 99;left:0;padding: 10px 10px 10px 24px;display: flex;">
                    <div>
                        <a-button class="blue-btn" type="primary" @click="returnClick()">返回</a-button>
                        <a-button style="margin-left: 10px;" class="blue-btn" type="primary" @click="refreshClick()">刷新</a-button>
                    </div>
                    <div style="margin-left: 50px;">
                        <a-button class="blue-btn" type="primary" @click="linkHandling('submitFlow')">办理</a-button>
                        <a-button style="margin-left: 10px;" class="blue-btn" type="primary" @click="departmentTransfer('innerChangeFlowJob')">转办</a-button>
                        <a-button style="margin-left: 10px;" class="blue-btn" type="primary" @click="returnGovernmentServices('returnZwfwxt')">退回政务服务</a-button>
                    </div>
                </div>
                <div style="width: 100%;height: 25px;"></div>

                <eventSet :key="eventSetKey" ref="eventSetRef" :parameter="parameterData" @successReturn="successReturn" @updatedSuccess="updatedSuccess"/>
                <processingConditionsAll ref="processingConditionsAllRef" :processingData="processingData" @interfaceSuccessful="interfaceSuccessful"></processingConditionsAll>
                <supplementaryRectification ref="supplementaryRectificationRef" @rectificationSuccess="rectificationSuccess"/>
            </a-spin>
        </a-modal>
    </div>
</template>
<script>

import {addSqsxBasicServe,innerChangeFlowJob} from './service/index'
import compSelector from '@/components/compSelector/compSelector'
import eventSet from './eventSet.vue'
export default {
    components:{
        compSelector,
        eventSet
    },
    props:{
        addEditParameter:{
            type:[Array,Object],
            default: () => {},
            required:false
        }
    },
    data(){
        return{
            processingData:{},
            typeSelect:'Select',
            visibleShow:false,
            confirmLoading:false,
            formState:{ksfl:''},
            formRequer:'',
            spinningKey:null,
            submittedSuccessfully:false,
            parameterData:{},
            eventSetKey:null,
        }
    },
    computed: {
        modalSpinningPrice(){
            return this.$store.state.permission.modalSpinningPrice
        },
    },
    watch:{
        // addEditParameter: {
        //     handler (newval, oldVal) {
        //         this.cancelLoading()
        //         //console.log('获取到了什么',newval)
        //         this.parameterData = newval
        //         this.formState.ksfl = ''
        //         if(!newval.sqsxid){
        //             addSqsxBasicServe().then(res=>{
        //                 //console.log(res)
        //                 //console.log('有进来这里吗？',res)
        //                 if(res.code == 200){
        //                     this.parameterData.sqsxid = res.result.sqsx.id
        //                     this.parameterData.jobid = res.result.job.id
        //                 }
        //             })
        //         }
        //     },
        //     deep: true
        // },
        
    },
    mounted(){
    },
    methods:{
        getData(val){
            //console.log(val,88888888888)
            if(!val.sqsxid){
                addSqsxBasicServe().then(res=>{
                    //console.log(res)
                    //console.log('有进来这里吗？',res)
                    if(res.code == 200){
                        this.parameterData.sqsxid = res.result.sqsx.id
                        this.parameterData.jobid = res.result.job.id
                        this.parameterData.nextNode  = res.result.nextNode
                        this.parameterData.nextNodeDbrList = res.result.nextNodeDbrList
                        val.sqsxid = res.result.sqsx.id
                        val.jobid = res.result.job.id
                        val.nextNode = res.result.nextNode
                        val.nextNodeDbrList = res.result.nextNodeDbrList
                        this.$nextTick(()=>{
                            this.$refs.eventSetRef.getDatas(val)
                        })
                    }
                })
            }else{
                this.$nextTick(()=>{
                    this.$refs.eventSetRef.getDatas(val)
                })
            }
            
        },
        cancelFalse(){
            this.cancelLoading()
        },
        updatedSuccess(){
            this.cancelLoading()
        },
        cancelLoading(){
            //console.log('我再刷新')
            this.$store.dispatch('UpdateSpinningPrice', {key:true,stateKey:'modalSpinningPrice'})
        },
        returnClick(){//返回
            this.visibleShow = false
        },
        refreshClick(){
            this.$emit('reviseClick',this.addEditParameter)
            this.spinningKey = Date.now()
            this.eventSetKey = Date.now()
            this.cancelLoading()
        },
        transferClick(){//转办
            var that = this
            if(this.formState.ksfl){
                this.$confirm({
                    title:'您确认要转办吗？',
                    // icon: createVNode(ExclamationCircleOutlined),
                    onOk() {
                        innerChangeFlowJob({jobid:that.parameterData.jobid,ksfl:that.formState.ksfl}).then(res=>{
                            if(res.code == 200){
                                that.$store.dispatch('UpdateSpinningPrice', 
                                {key:true,stateKey:'modalSpinningPrice'}).then(() => {
                                    that.successReturn(false)
                                    that.$message.success(res.message)
                                })
                                
                            }else{
                                that.$store.dispatch('UpdateSpinningPrice', {key:false,stateKey:'modalSpinningPrice'})
                                that.$message.warning(res.message)
                            }
                        })
                    },
                    
                });
            }else{
                this.$message.warning('请选择转办科室')
            }
            
        },
        preserveClick(){//保存
            // this.$store.dispatch('UpdateSpinningPrice', {key:'true',stateKey:'modalSpinningPrice'})
            this.$refs.dealWithRef.handlePreserve()
        },
        submitClick(){//提交
            // this.$store.dispatch('UpdateSpinningPrice', {key:'true',stateKey:'modalSpinningPrice'})
            this.$refs.dealWithRef.shandleSubmit()
        },
        successReturn(val){
            this.visibleShow = val
            this.$emit('successReturn')
        },
        interfaceSuccessful(val){
            this.successReturn(val)
        },
        rectificationSuccess(){
            this.successReturn(false)
        },
        linkHandling(val){
            //console.log(this.addEditParameter)
            let result = this.$refs.eventSetRef.$refs.dealWithRef.shandleSubmit()
            if(result){
                this.$refs.processingConditionsAllRef.processingConditionsVisible = true
                let data = {
                    interface:val,
                    sqsxid:this.addEditParameter.sqsxid,
                    nextNodeDbrList:this.addEditParameter.nextNodeDbrList,
                    nextNode:this.addEditParameter.nextNode,
                    jobid:this.addEditParameter.jobid,
                    headerLeftTitle:'办理',
                    headerCenterTitle:'药品流通查验--任务受理',
                }
                this.processingData = data
                
                this.$refs.processingConditionsAllRef.getData(data)
            }
        },
        departmentTransfer(val){
            this.$refs.eventSetRef.$refs.dealWithRef.handlePreserve()
            this.$refs.processingConditionsAllRef.processingConditionsVisible = true
            let data = {
                interface:val,
                sqsxid:this.addEditParameter.sqsxid,
                jobid:this.addEditParameter.jobid,
                isBlyj:false,
                isZbxx:true,
                isXyb:false,
                headerLeftTitle:'转办',
                headerCenterTitle:'药品流通查验--任务受理',
            }
            this.processingData = data
            
            this.$refs.processingConditionsAllRef.getData(data)
        },
        returnGovernmentServices(val){
            this.$refs.supplementaryRectificationRef.visible = true
            this.$refs.supplementaryRectificationRef.getData(
                {interfaceValue:val,modalTitle:'退回政务服务',
                isTextMessage:false,sqsxid:this.addEditParameter.sqsxid,
                isTime:false,jobid:this.addEditParameter.jobid},
                {opinion:'thyy'}
            )
        },
    }

}

</script>
<style lang="less">
/* .ant-form-item-label{
    font-weight: 600;
} */

 .ant-modal-title{
    font-weight: 600;
 }
 .ant-modal-header{
    background: #5ca3e5;
 }
 .ant-modal-footer .ant-btn-primary{
    border: 1px solid #5ca3e5 !important;
    background-color: #5ca3e5 !important;
    color: #fff !important;
 }
 .acceptance-modal .ant-modal-header{
    display: none !important;
 }
 .acceptance-modal .ant-modal-footer{
    display: none !important;
 }
 .acceptance-modal .ant-modal-content{
    height: 100vh;
    overflow: auto;
 }
 .full-modal {
  .ant-modal {
    max-width: 100%;
    top: 0;
    padding-bottom: 0;
    margin: 0;
  }
  .ant-modal-content {
    width: 100%;
    display: flex;
    flex-direction: column;
    height: calc(100vh);
  }
  .ant-modal-body {
    flex: 1;
  }
}
</style>